package com.woniu.job.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MyBirthdate {

    public static String age(java.util.Date brithday) throws Exception {
        if (brithday == null) {
            return "无";
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(brithday);
        int year = cal.get(Calendar.YEAR);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(new java.util.Date());
        int year2 = cal2.get(Calendar.YEAR);
        year2 = year2 - year;
        return String.valueOf(year2);
    }

    public static String ageex(String brithday) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//小写的mm表示的是分钟
        java.util.Date date = sdf.parse(brithday);
        return age(date);
    }
}
